package com.onlinemusic.controller;

import com.onlinemusic.common.R;
import com.onlinemusic.pojo.request.CartListRequest;
import com.onlinemusic.service.CartListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("cart")
public class CartController {

    @Autowired
    private CartListService cartListService;

    /**
     * 加入购物车
     *
     * @param cartListRequest
     * @return
     */
    @PostMapping("add")
    public R addServerCart(@RequestBody CartListRequest cartListRequest) {
        return cartListService.addCartList(cartListRequest);
    }

    /**
     * 返回所有购物车项
     *
     * @param userId
     * @return
     */
    @GetMapping("list")
    public R getCartList(@RequestParam("userId") Integer userId) {
        return cartListService.allCartList(userId);
    }

    /**
     * 删除购物车项
     *
     * @param songIds
     * @return
     */
    @GetMapping("remove")
    public R removeCartList(@RequestParam("userId") Integer userId, @RequestParam("cartListIds") List<Integer> songIds) {
        return cartListService.deleteCartList(userId, songIds);
    }

}
